<?php
class Admin_model_goods extends Core_model_abstract
{
	public function __construct()
	{
		parent::__construct('goods');
	}
	
	protected function _setAutoIncrementFields() 
	{
		return array(
			'id'
		);
	}

	protected function _setFields() 
	{
		return array(
			'id',        //id
			'goodsName', //商品名称
			'price',     //单价
			'unit',      //单位
			'weight',    //重量
			'freight',   //运费
			'cateID',    //所属分类
			'urlName',   //URL名称
			'keyWords',  //页面关键字
			'desc',      //页面描述
			'createDate',   //创建时间
			'createPerson', //创建人
			'modifyDate',   //修改时间
			'modifyPerson'  //修改人
		);
	}
	
	public function add($goodsData)
	{
		$goodsData = $this->_getFieldsData($goodsData);
		$goodsData['createDate'] = time();
		return $this->_insert($goodsData);
	}
	
	public function getGoodsForCateID($cateID)
	{
		$cateID = intval($cateID);
		$param = array();
		if($cateID > 0)
		{
			$param['where'] = "`cateID`='{$cateID}'";
		}
		$param['fileds'] = array(
			'id', 'goodsName', 'unit', 
			'price', 'weight', 'freight', 
			'urlName', 'keyWords', 'desc');
		$param['orderby'] = '`id` DESC';
		$param['limit'] = '0';
		return $this->_select($param);
	}
	
	public function getGoods($goodsID)
	{
		$goodsID = intval($goodsID);
		if($goodsID < 1)
		{
			return array();
		}
		
		$param['where'] = "`id`='{$goodsID}'";
		$goods = $this->_select($param);
		if(empty($goods))
		{
			return array();
		}
		return $goods[0];
	}

	protected function _setForeignKeyRelation() 
	{
		return array();
	}

	protected function _setPrimaryKeys() 
	{
		return array(
			'id'
		);
	}

	protected function _validationField($fieldName, $value) 
	{
		return true;
	}
}